package zozopo.warehouse;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.SupplierOS;
import zozopo.warehouse.operations.SupplierTB;
import zozopo.warehouse.operations.WarehouseOS;
import zozopo.warehouse.operations.WarehouseTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ModifySupplierAction extends ActionSupport implements Action,SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String limitedCode ="WAREHOUSE.SUPPLIER.MODIFY";
	
	//传入参数
	private String id_supplier = "";
	private String name_supplier = "";
	private String address_supplier = "";
	private String phone_supplier = "";
	private String mobile_supplier = "";
	private String qq_supplier = "";
	private String manager_supplier = "";

	private String remark_supplier = "";
	
	//传出参数
	private SupplierTB supplier;
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		//权限处理
		
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
		
		
		SupplierOS supplierOS = new SupplierOS();
		supplier = new SupplierTB();
		

		supplier.setAddress_supplier(address_supplier);
		supplier.setId_supplier(id_supplier);
		supplier.setManager_supplier(manager_supplier);
		supplier.setMobile_supplier(mobile_supplier);
		supplier.setName_supplier(name_supplier);
		supplier.setPhone_supplier(phone_supplier);
		supplier.setQq_supplier(qq_supplier);
		supplier.setRemark_supplier(remark_supplier);
		supplier.setUseremail_supplier(operator.getEmail_operator());
		supplier.setUsername_supplier(operator.getName_operator());
		
		
		if(!supplierOS.upadteSupplier(supplier)){
			supplierOS.releaseConnection();
			return ERROR;
		}
		
		supplier = supplierOS.getSupplierById(id_supplier);
		
		supplierOS.releaseConnection();
		
		return SUCCESS;
	}
	
	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有修改供应商权限.");
			return;
		}
		
		
	}
	public String getId_supplier() {
		return id_supplier;
	}
	public void setId_supplier(String id_supplier) {
		this.id_supplier = id_supplier;
	}
	public String getName_supplier() {
		return name_supplier;
	}
	public void setName_supplier(String name_supplier) {
		this.name_supplier = name_supplier;
	}
	public String getAddress_supplier() {
		return address_supplier;
	}
	public void setAddress_supplier(String address_supplier) {
		this.address_supplier = address_supplier;
	}
	public String getPhone_supplier() {
		return phone_supplier;
	}
	public void setPhone_supplier(String phone_supplier) {
		this.phone_supplier = phone_supplier;
	}
	public String getMobile_supplier() {
		return mobile_supplier;
	}
	public void setMobile_supplier(String mobile_supplier) {
		this.mobile_supplier = mobile_supplier;
	}
	public String getQq_supplier() {
		return qq_supplier;
	}
	public void setQq_supplier(String qq_supplier) {
		this.qq_supplier = qq_supplier;
	}
	public String getManager_supplier() {
		return manager_supplier;
	}
	public void setManager_supplier(String manager_supplier) {
		this.manager_supplier = manager_supplier;
	}
	public String getRemark_supplier() {
		return remark_supplier;
	}
	public void setRemark_supplier(String remark_supplier) {
		this.remark_supplier = remark_supplier;
	}
	public SupplierTB getSupplier() {
		return supplier;
	}
	public void setSupplier(SupplierTB supplier) {
		this.supplier = supplier;
	}
	public static String getLimitedcode() {
		return limitedCode;
	}

}
